package com.cmwa.scbp.sys.msg.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cmwa.scbp.base.mvc.entity.Employee;
import com.cmwa.scbp.base.mvc.entity.Page;
import com.cmwa.scbp.base.mvc.entity.SearchParam;
import com.cmwa.scbp.sys.msg.dao.IMsgViewDao;
import com.cmwa.scbp.sys.msg.service.IMsgViewService;
import com.cmwa.scbp.sys.msg.vo.MsgViewVo;
import com.cmwa.scbp.utils.SessionUtils;

@Service
public class MsgViewServiceImpl  implements IMsgViewService{
	@Resource
	private IMsgViewDao msgViewDao;
	
	public Page<MsgViewVo> msgViewListPage(SearchParam sp){
		Employee employee = SessionUtils.getEmployee();// 当前的登录用户
		List<MsgViewVo> items = new ArrayList<MsgViewVo>();
		if(employee != null && StringUtils.isNotBlank(employee.getID())) {
			sp.getSp().put("empId", employee.getID());
			items = msgViewDao.msgViewListPage(sp);
		}
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}


	@Override
	public Page<MsgViewVo> newestListPage(SearchParam sp) {
		Employee employee = SessionUtils.getEmployee();// 当前的登录用户
		List<MsgViewVo> items = new ArrayList<MsgViewVo>();
		if(employee != null && StringUtils.isNotBlank(employee.getID())) {
			sp.getSp().put("empId", employee.getID());
			items = msgViewDao.newestListPage(sp);
		}
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}
	
	@Override
	public Page<MsgViewVo> flagListPage(SearchParam sp) {
		Employee employee = SessionUtils.getEmployee();// 当前的登录用户
		List<MsgViewVo> items = new ArrayList<MsgViewVo>();
		if(employee != null && StringUtils.isNotBlank(employee.getID())) {
			sp.getSp().put("empId", employee.getID());
			items = msgViewDao.flagListPage(sp);
		}
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public void updateForView(String msgId) {
		msgViewDao.updateForView(msgId);
	}

	@Override
	public void updateForFlag(String msgId, String flag) {
		msgViewDao.updateForFlag(msgId, flag);
		msgViewDao.updateForView(msgId);
	}

	@Override
	public void deleteMsg(String msgId) {
		msgViewDao.deleteMsg(msgId);
	}

	@Override
	public void batchDeleteMsg(List<String> msgIdList) {
		msgViewDao.batchDeleteMsg(msgIdList);
	}


	@Override
	public void addMsg(MsgViewVo msg) {
		msgViewDao.addMsg(msg);
	}


	@Override
	public void batchAddMsg(List<MsgViewVo> msgList) {
		msgViewDao.batchAddMsg(msgList);
	}


	@Override
	public int unreadMsgCount() {
		Employee employee = SessionUtils.getEmployee();// 当前的登录用户
		if(employee != null && StringUtils.isNotBlank(employee.getID())) {
			return msgViewDao.unreadMsgCount(employee.getID());
		}
		return 0;
	}

}
